package com.manage.demo.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.manage.demo.dao.model.ClassInfo;

@Mapper
public interface CourseinfoMapper {

	@Select("select grade from class_info group by grade")
	public List<String> getGrades();

	@Select("select "
			+ "a.*,b.name,c.course_name "
			+ "from class_info as a inner join teacher_info as b "
			+ "on a.tch_id=b.tch_id "
			+ "inner join course_info as c "
			+ "on a.course_id=c.course_id "
			+ "where "
			+ "(#{tchid}='' or a.tch_id=#{tchid}) "
			+ "and (#{grades}='' or a.grade=#{grades}) "
			+ "and (#{classes}='' or a.class_num=#{classes}) "
			+ "and (#{tchname}='' or b.name=#{tchname}) "
			+ "order by grade, class_num "
			+ "limit #{limit} "
			+ "offset #{offset}")
	public List<Map<String, Object>> getclasslist(String classes, String grades, String tchid, String tchname, int limit, int offset);

	@Select("select "
			+ "count(*) as count "
			+ "from class_info as a inner join teacher_info as b "
			+ "on a.tch_id=b.tch_id "
			+ "inner join course_info as c "
			+ "on a.course_id=c.course_id "
			+ "where "
			+ "(#{tchid}='' or a.tch_id=#{tchid}) "
			+ "and (#{grades}='' or a.grade=#{grades}) "
			+ "and (#{classes}='' or a.class_num=#{classes}) "
			+ "and (#{tchname}='' or b.name=#{tchname})")
	public List<Map<String, Object>> getclassCount(String classes, String grades, String tchid, String tchname);

	@Select("select tch_id, name from teacher_info")
	public List<Map<String, String>> getTchId();

	@Select("select tch_id, name from teacher_info where subject='01'")
	public List<Map<String, String>> getChineseTchId();

	@Select("select tch_id, name from teacher_info where subject='02'")
	public List<Map<String, String>> getMathTchId();

	@Select("select tch_id, name from teacher_info where subject='03'")
	public List<Map<String, String>> getEnglishTchId();

	@Select("select tch_id, name from teacher_info where subject='04'")
	public List<Map<String, String>> getPhysicsTchId();

	@Select("select tch_id, name from teacher_info where subject='05'")
	public List<Map<String, String>> getChemistryTchId();

	@Update("update class_info set tch_id=#{tch_id} where id=#{id}")
	public Integer updateclass(String tch_id, String id);
}
